package org.example.ReflectDemo.test1;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class JDKInvocationHandler implements InvocationHandler{
    private Object target;
    public JDKInvocationHandler(Object target) {
        this.target = target;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 代理增强内容
        System.out.println("我是中介, 开始代理");
        //通过反射调⽤被代理类的⽅法
        Object retVal = method.invoke(target, args);
        //代理增强内容
        System.out.println("我是中介, 代理结束");
        return retVal;

    }
}
